﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Activities.DAL.Utility
{
    public class DateTimeHelper
    {
        public static string ValidateDate(string dateStr)
        {
            try
            {
                DateTime date = DateTime.Parse(dateStr);
                if (date.Year > DateTime.Now.Year)
                {
                    return "Invalid value for year: " + date.Year + " - must be between 1902 and " + DateTime.Now.Year;
                }
                else
                {
                    return "True";
                }

            }
            catch
            {
                return "Invalid date format: " + dateStr;
            }
        }

        public static string DateFormat(string date)
        {
            try
            {
                System.IFormatProvider format = new System.Globalization.CultureInfo("en-US");
                DateTime newdate = DateTime.Parse(date, format);
                string resultdate = newdate.ToString("yyyy-MM-dd");
                return resultdate;
            }
            catch(Exception ex)
            {
                throw ex;
            }
            

        }
    }
}
